#pragma once

#include <string>

#include "Protocal.hpp"

class ServerCal
{
public:
    std::string Calculator(std::string& package)
    {
        Request req;
        if (req.Deserialize(package) == false)
            return "";
        Response resp;
        switch (req._oper)
        {
        case '+':
            resp._result = req._left + req._right;
            resp._exitcode = Response::RESPONSE_SUCCESS;
            break;
        case '-':
            resp._result = req._left - req._right;
            resp._exitcode = Response::RESPONSE_SUCCESS;
            break;
        case '*':
            resp._result = req._left * req._right;
            resp._exitcode = Response::RESPONSE_SUCCESS;
            break;
        case '/':
            if (req._right == 0)
            {   
                resp._exitcode = Response::RESPONSE_DIV_ZERO;
                break;
            }
            resp._result = req._left / req._right;
            resp._exitcode = Response::RESPONSE_SUCCESS;
            break;
        case '%':
            if (req._right == 0)
            {   
                resp._exitcode = Response::RESPONSE_DIV_ZERO;
                break;
            }
            resp._result = req._left % req._right;
            resp._exitcode = Response::RESPONSE_SUCCESS;
            break;
        default:
            resp._result = 0;
            resp._exitcode = Response::RESPONSE_UNKONW_OPER;
            break;
        }
        std::string result;
        resp.Serialize(result);
        return result;
    }
};